<template>
  <el-dialog title="分配角色" :visible="roleShow" @close="closeBtn">
    <el-checkbox-group v-model="checkList">
      <el-checkbox v-for="itm in roleList" :key="itm.id" :label="itm.id">{{ itm.name }}</el-checkbox>
    </el-checkbox-group>
    <el-row type="flex" justify="center" style="margin-top:30px">
      <el-button type="primary" size="small" @click="isOkBtn">确定</el-button>
      <el-button size="small" @click="closeBtn">取消</el-button>
    </el-row>
  </el-dialog>
</template>

<script>
import { getAllUser } from '@/api/setting'
import { getDetailById, assignRoles } from '@/api/employees'
export default {
  props: {
    roleShow: {
      type: Boolean,
      required: true
    },
    id: {
      type: [String, Number],
      required: true
    }
  },
  data() {
    return {
      // 选中列表
      checkList: [],
      //   角色列表
      roleList: []
    }
  },
  created() {
    this.getRoleList()
  },
  methods: {
    //   获取所有角色列表
    async getRoleList() {
      const { rows } = await getAllUser()
      this.roleList = rows
    },
    // 根据ID获取角色
    async getRoleById(id) {
      const { roleIds } = await getDetailById(id)
      this.checkList = roleIds
    },
    async isOkBtn() {
      await assignRoles({
        id: this.id,
        roleIds: this.checkList
      })
      this.$emit('update:roleShow', false)
    },
    closeBtn() {
      this.$emit('update:roleShow', false)
    }
  }
}
</script>

<style>

</style>
